const express = require('express');
const router = express.Router();
const {
  getNoticeAll,
  addNotice,
  deleteNotice,
} = require('../../services/index');

const { verifyToken, checkRole } = require('../auth');

//查看所有公告
router.get('/', verifyToken, async (req, res) => {
  let result = await getNoticeAll();
  res.json(result);
});

//添加公告，管理员权限、交管部门权限
router.post(
  '/addNotice',
  verifyToken,
  checkRole(['admin', 'traffic']),
  async (req, res) => {
    let result = await addNotice(req.body);
    res.json(result);
  }
);

//删除公告，管理员权限、交管部门权限
router.delete(
  './deleteNotice',
  verifyToken,
  checkRole(['admin', 'traffic']),
  async (req, res) => {
    let result = await deleteNotice(req.body.id);
    res.json(result);
  }
);

module.exports = router;
